home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 11 - 1995 / 11.02 Feb 95 / Yenta / PrefsWindowƒ / CPPPrefsWindow.cp next >
Encoding:
Text File  |  1996-04-04  |  6.6 KB  |  253 lines  |  [TEXT/KAHL]

  1. /***************************************************** IMPLEMENTATION
  2.     DATE:    9/26/93
  3.     AUTHOR: Eric R. Rosé
  4.  
  5.     CLASS:  CPPPrefsWindow
  6.     
  7.     SUPERCLASS: CPPWindow
  8.     
  9.         This C++ class manages the NetApp preferences window
  10.     
  11. ********************************************************************/
  12.  
  13. #include "CPPPrefsWindow.h"
  14. #include <CPPWindowManager.h>
  15. #include <CPPButton.h>
  16. #include <CPPCheckBox.h>
  17. #include <CPPStaticText.h>
  18. #include <CPPIntText.h>
  19. #include <ToolboxTools.h>
  20.  
  21. #define    prefsWindowID    202
  22.  
  23. extern    CPPWindowManager    *gWindowManager;
  24. extern    void DoStdOKButton (CPPWindow *theWindow);
  25. extern    void DoStdCancelButton (CPPWindow *theWindow);
  26.  
  27. /*-----------------------------------------------------------------*/
  28.  
  29.     void DoScanClick (CPPWindow *theWindow)
  30.     /* If the checkbox is unchecked, set the value of 'scan' to 0 */
  31.     /* Otherwise, set it to a default value */
  32.     {
  33.         CPPPrefsWindow *ourWindow = (CPPPrefsWindow *)theWindow;
  34.         
  35.         if (ourWindow)
  36.           {
  37.               if (ourWindow->doScan->GetValue())
  38.                 {
  39.                     ourWindow->scanRate->MakeVisible(TRUE);
  40.                     ourWindow->MakeTarget(ourWindow->scanRate);
  41.                 }
  42.               else
  43.                 {
  44.                     if (ourWindow->GetTarget() == ourWindow->scanRate)
  45.                       if (!ourWindow->MakeNextTarget())
  46.                         ourWindow->MakeTarget (NULL);
  47.                     ourWindow->scanRate->MakeVisible(FALSE);
  48.                 }
  49.           }
  50.     }
  51.  
  52. /*-----------------------------------------------------------------*/
  53.  
  54.     void DoConfirmClick (CPPWindow *theWindow)
  55.     /* If the checkbox is unchecked, set the value of 'confirm' to 0 */
  56.     /* Otherwise, set it to a default value */
  57.     {
  58.         CPPPrefsWindow *ourWindow = (CPPPrefsWindow *)theWindow;
  59.         
  60.         if (ourWindow)
  61.           {
  62.               if (ourWindow->doConfirm->GetValue())
  63.                 {
  64.                     ourWindow->confirmRate->MakeVisible(TRUE);
  65.                     ourWindow->MakeTarget(ourWindow->confirmRate);
  66.                 }
  67.               else
  68.                 {
  69.                     if (ourWindow->GetTarget() == ourWindow->confirmRate)
  70.                       if (!ourWindow->MakeNextTarget())
  71.                         ourWindow->MakeTarget (NULL);
  72.                     ourWindow->confirmRate->MakeVisible(FALSE);
  73.                 }
  74.           }
  75.     }
  76.  
  77. /*-----------------------------------------------------------------*/
  78. /*------------------------ PUBLIC METHODS -------------------------*/
  79. /*-----------------------------------------------------------------*/
  80.  
  81.     CPPPrefsWindow::CPPPrefsWindow (CPPWindowManager *theManager,
  82.                             PrefsData *initData) : 
  83.                     CPPWindow (theManager, prefsWindowID)
  84.     {
  85.         GrafPtr    SavePort;
  86.         Rect    tempRect;
  87.         CPPStaticText    *ST, *ST2;
  88.         
  89.         GetPort(&SavePort);
  90.         SetPort(this->theWindow);
  91.         
  92.     //    create static text items
  93.         SetRect (&tempRect, 250, 62, 306, 78);
  94.         ST2 = new CPPStaticText ((CPPWindow *)this, &tempRect, "\pminutes", systemFont, 12);
  95.  
  96.         SetRect (&tempRect, 235, 90, 291, 106);
  97.         ST = new CPPStaticText ((CPPWindow *)this, &tempRect, "\pminutes", systemFont, 12);
  98.         
  99.     //    create edit text areas
  100.         SetRect (&tempRect, 221, 62, 249, 78);
  101.         confirmRate = new CPPIntText ((CPPWindow *)this, &tempRect,
  102.                                    initData->confirmRate, 
  103.                                    2, systemFont, 12);
  104.         if (!initData->confirmRate)
  105.           confirmRate->MakeVisible(FALSE);
  106.  
  107.         SetRect (&tempRect, 206, 90, 234, 106);
  108.         scanRate = new CPPIntText ((CPPWindow *)this, &tempRect,
  109.                                    initData->scanRate, 2, 
  110.                                    systemFont, 12);
  111.         if (!initData->scanRate)
  112.           scanRate->MakeVisible(FALSE);
  113.         
  114.     // create the 'sound' checkboxes          
  115.         playMessage = new CPPCheckBox ((CPPWindow *)this, 129,
  116.                                      initData->playMessage, FALSE);
  117.         playLogon = new CPPCheckBox ((CPPWindow *)this, 135,
  118.                                      initData->playLogon, FALSE);
  119.  
  120.     // create the 'scan' checkboxes and edit areas
  121.         doScan = new CPPCheckBox ((CPPWindow *)this, 131,
  122.                                      (initData->scanRate != 0), 
  123.                                      FALSE);
  124.         doScan->SetDoClickProc (DoScanClick);
  125.  
  126.         doConfirm = new CPPCheckBox ((CPPWindow *)this, 130,
  127.                                      (initData->confirmRate != 0), 
  128.                                      FALSE);
  129.         doConfirm->SetDoClickProc (DoConfirmClick);
  130.                                      
  131.  
  132.     // create the dialog buttons
  133.         okButton = new CPPButton ((CPPWindow *)this, 133, TRUE);
  134.         okButton->SetDoClickProc (DoStdOKButton);
  135.  
  136.         cancelButton = new CPPButton ((CPPWindow *)this, 134, FALSE);
  137.         cancelButton->SetDoClickProc (DoStdCancelButton);
  138.  
  139.         SetRect (&tempRect, 250, 62, 306, 78);
  140.  
  141.         this->MakeNextTarget ();
  142.         
  143.         SetPort(SavePort);
  144.  
  145.     }
  146.     
  147. /*-----------------------------------------------------------------*/
  148.  
  149.     CPPPrefsWindow::~CPPPrefsWindow ()
  150.     {
  151.         
  152.     }
  153.  
  154. /*-----------------------------------------------------------------*/
  155.  
  156.     char    *CPPPrefsWindow::ClassName (void)
  157.     {
  158.         return "CPPPrefsWindow";
  159.     }
  160.     
  161. /*-----------------------------------------------------------------*/
  162.  
  163.     void    CPPPrefsWindow::GetDialogData (PrefsData *theData)
  164.     /* copy the data from the window into the provided structure */
  165.     {
  166.         if (theData)
  167.           {
  168.             theData->scanRate = 
  169.                 doScan->GetValue() ? scanRate->GetAsInt() : 0;
  170.             
  171.             theData->confirmRate = 
  172.                 doConfirm->GetValue() ? confirmRate->GetAsInt() : 0;
  173.             
  174.             if (playMessage->GetValue())
  175.               theData->playMessage = TRUE;
  176.             else
  177.               theData->playMessage = FALSE;
  178.               
  179.             if (playLogon->GetValue())
  180.               theData->playLogon = TRUE;
  181.             else
  182.               theData->playLogon = FALSE;
  183.           }
  184.     }
  185.  
  186. /*-----------------------------------------------------------------*/
  187.  
  188.     Boolean    CPPPrefsWindow::DoUserKey (EventRecord *theEvent)
  189.     {
  190.         char theKey;
  191.         CPPList    *TempList;
  192.  
  193.         theKey = theEvent->message & charCodeMask;
  194.         if (!(theEvent->modifiers & cmdKey))
  195.           {
  196.               switch (theKey) {
  197.                   case kTab :
  198.                       if (ShiftKeyDown(theEvent->modifiers))
  199.                         {MakePreviousTarget(); return TRUE;}
  200.                       else
  201.                         {MakeNextTarget(); return TRUE;}
  202.                       break;
  203.                   case kEscape :
  204.                       if (cancelButton)
  205.                         cancelButton->SimulateClick();
  206.                     return TRUE;
  207.                     break;
  208.                   case kEnter :
  209.                       if (okButton)
  210.                         okButton->SimulateClick();
  211.                       return TRUE;
  212.                       break;
  213.                   default:
  214.                       return CPPWindow::DoUserKey (theEvent);
  215.                       break;
  216.             } // switch
  217.           }
  218.         else
  219.           {
  220.             if (theKey == '.')
  221.               {
  222.                 if (cancelButton)
  223.                   cancelButton->SimulateClick();
  224.                   return TRUE;
  225.               }
  226.             else
  227.               return CPPWindow::DoUserKey (theEvent);
  228.           }
  229.     }
  230.  
  231. /*-----------------------------------------------------------------*/
  232.     
  233.     Boolean    DoPrefsWindow (PrefsData *initData)
  234.     {
  235.         CPPPrefsWindow    *theWindow;
  236.         Boolean            theResult;
  237.         
  238.         theWindow = new CPPPrefsWindow (gWindowManager, initData);
  239.           
  240.         if (theWindow)
  241.           {
  242.               theWindow->DoModalWindow ();
  243.               if ((theResult = theWindow->modalResult))
  244.                 theWindow->GetDialogData (initData);
  245.               delete theWindow;
  246.               return theResult;
  247.           }
  248.         else
  249.           {
  250.               ErrorAlert (MemError(), "\pCould not show the 'prefs' dialog");
  251.             return FALSE;
  252.           }
  253.     }